package Model;

import Model.permission.Permission;

import java.util.ArrayList;
import java.util.List;

public interface GeneralUser {

    public String getUser_number ();
    public String getUser_name ();
    public Integer getRole_id ();
    public Integer getUser_id ();
    public List<Permission> getPermissions();
    public void setPermissions(List<Permission> allPermissions);

    class UserUtil{
        public static List<Permission> getNoneRootPermissions(List<Permission> allPermissions) {
            List<Permission> permissions = new ArrayList<>(allPermissions.size());
            for(Permission each: allPermissions){
                if(each == null){
                    continue;
                }
                String path = each.getPath();
                if(path == null){ continue; }
                if(! (path.length() == 1 && path.charAt(0) == '/')){
                    permissions.add(each);
                }
            }
            return permissions;
        }
    }

}
